package com.semanticweb.webapp.model.ontology;

import org.apache.lucene.document.Document;

import com.semanticweb.webapp.ontology.CType;
import com.semanticweb.webapp.ontology.OntHelper;
import com.semanticweb.webapp.search.IDocument;

/**
 * Class which represents 'sirina', 'visina', 'precnik', 'tezina', 'debljina', 'duzina' from the chart depending on
 * Type.
 * 
 * @author Lab
 * 
 */
public class Dimension extends DefaultAbstractEntity<Double> implements IDocument {

    private String measurementUnit;
    private final Type type;

    public Dimension(final String id, final Type type) {
        super(id);
        this.type = type;
    }

    public enum Type {
        WIDTH, HEIGHT, RADIUS, WEIGHT, THICKNESS, LENGTH
    }

    @Override
    public void toRDF() {

        switch (this.type) {
        case HEIGHT:
            toDimensionRDF(CType.HEIGHT);
            break;
        case LENGTH:
            toDimensionRDF(CType.LENGTH);
            break;
        case RADIUS:
            toDimensionRDF(CType.RADIUS);
            break;
        case THICKNESS:
            toDimensionRDF(CType.THICKNESS);
            break;
        case WEIGHT:
            toDimensionRDF(CType.WEIGHT);
            break;
        case WIDTH:
            toDimensionRDF(CType.WIDTH);
            break;
        }
    }

    public void fromRDF() {
        switch (this.type) {
        case HEIGHT:
            fromDimensionRDF(CType.HEIGHT);
            break;
        case LENGTH:
            fromDimensionRDF(CType.LENGTH);
            break;
        case RADIUS:
            fromDimensionRDF(CType.RADIUS);
            break;
        case THICKNESS:
            fromDimensionRDF(CType.THICKNESS);
            break;
        case WEIGHT:
            fromDimensionRDF(CType.WEIGHT);
            break;
        case WIDTH:
            fromDimensionRDF(CType.WIDTH);
            break;
        }
    }

    private void toDimensionRDF(final CType type) {
        OntHelper.toRDFDimension(this.id, this.value, this.measurementUnit, type);
    }

    private void fromDimensionRDF(final CType type) {
        this.value = OntHelper.fromRDFDimensionValue(this.id, type);
        this.measurementUnit = OntHelper.fromRDFDimensionUnit(this.id, type);
    }

    public Type getType() {
        return this.type;
    }

    public String getMeasurementUnit() {
        return this.measurementUnit;
    }

    public void setMeasurementUnit(final String measurementUnit) {
        this.measurementUnit = measurementUnit;
    }

    @Override
    public void toIndexDocument(final Document doc) {
        // nothing to index
    }
}
